package com.example.spring.demo.controller;

import com.example.spring.demo.dto.UserDto;
import com.example.spring.demo.entity.User;
import com.example.spring.demo.service.UserServiceImple;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liangchao
 * 11/18/18 4:55 PM
 */
@RestController
public class UserController {

    @Autowired
    private UserServiceImple userService;

    @ApiOperation("删除用户")
    @RequestMapping(value = "/user/{id}", method = RequestMethod.DELETE)
    public UserDto deleteUser(@PathVariable int id) {
        User user = userService.select(id);
        userService.delete(id);
//        return user;
        return null;
    }


    @ApiOperation(value = "获取用户信息")
    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    public UserDto selectUser(@PathVariable @ApiParam(value = "用户ID", example = "123") int id) {
        User user = userService.selectByUserId(id);
        return new UserDto();
    }


    @ApiOperation(value = "插入用户", notes = "用户信息要正确")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public UserDto insertUser(@RequestBody User user) {
        userService.insert(user);
//        return userService.select(user.getId());
        return null;
    }

    @ApiOperation(value = "更新用户", notes = "用户信息要正确")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public UserDto updateUser(@RequestBody @ApiParam(name = "要修改的用户", required = true) User user) {
        userService.updateById(user);
//        return userService.select(user.getId());
        return null;
    }

}
